package inventorysystem.dao;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

  
    
  
/**
 * This class was autogenerated by Torque on:
 *
 * [Sun Mar 21 15:11:40 CST 2010]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to ORF_Supply
 */
public abstract class BaseORF_Supply extends BaseObject
{
    /** The Peer class */
    private static final ORF_SupplyPeer peer =
        new ORF_SupplyPeer();

        
    /** The value for the oRF_SupplyID field */
    private int oRF_SupplyID;
      
    /** The value for the oRF_ID field */
    private int oRF_ID;
      
    /** The value for the user_ID field */
    private int user_ID;
      
    /** The value for the supply_name field */
    private String supply_name;
      
    /** The value for the supply_type field */
    private String supply_type;
      
    /** The value for the quantity field */
    private String quantity;
      
    /** The value for the status field */
    private String status;
      
    /** The value for the amount field */
    private String amount;
      
    /** The value for the unit field */
    private String unit;
      
    /** The value for the price field */
    private String price;
  
    
    /**
     * Get the ORF_SupplyID
     *
     * @return int
     */
    public int getORF_SupplyID()
    {
        return oRF_SupplyID;
    }

                        
    /**
     * Set the value of ORF_SupplyID
     *
     * @param v new value
     */
    public void setORF_SupplyID(int v) 
    {
    
                  if (this.oRF_SupplyID != v)
              {
            this.oRF_SupplyID = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the ORF_ID
     *
     * @return int
     */
    public int getORF_ID()
    {
        return oRF_ID;
    }

                              
    /**
     * Set the value of ORF_ID
     *
     * @param v new value
     */
    public void setORF_ID(int v) throws TorqueException
    {
    
                  if (this.oRF_ID != v)
              {
            this.oRF_ID = v;
            setModified(true);
        }
    
                          
                if (aORF != null && !(aORF.getORF_ID() == v))
                {
            aORF = null;
        }
      
              }
  
    /**
     * Get the User_ID
     *
     * @return int
     */
    public int getUser_ID()
    {
        return user_ID;
    }

                              
    /**
     * Set the value of User_ID
     *
     * @param v new value
     */
    public void setUser_ID(int v) throws TorqueException
    {
    
                  if (this.user_ID != v)
              {
            this.user_ID = v;
            setModified(true);
        }
    
                          
                if (aUser != null && !(aUser.getUser_ID() == v))
                {
            aUser = null;
        }
      
              }
  
    /**
     * Get the Supply_name
     *
     * @return String
     */
    public String getSupply_name()
    {
        return supply_name;
    }

                        
    /**
     * Set the value of Supply_name
     *
     * @param v new value
     */
    public void setSupply_name(String v) 
    {
    
                  if (!ObjectUtils.equals(this.supply_name, v))
              {
            this.supply_name = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Supply_type
     *
     * @return String
     */
    public String getSupply_type()
    {
        return supply_type;
    }

                        
    /**
     * Set the value of Supply_type
     *
     * @param v new value
     */
    public void setSupply_type(String v) 
    {
    
                  if (!ObjectUtils.equals(this.supply_type, v))
              {
            this.supply_type = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Quantity
     *
     * @return String
     */
    public String getQuantity()
    {
        return quantity;
    }

                        
    /**
     * Set the value of Quantity
     *
     * @param v new value
     */
    public void setQuantity(String v) 
    {
    
                  if (!ObjectUtils.equals(this.quantity, v))
              {
            this.quantity = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Status
     *
     * @return String
     */
    public String getStatus()
    {
        return status;
    }

                        
    /**
     * Set the value of Status
     *
     * @param v new value
     */
    public void setStatus(String v) 
    {
    
                  if (!ObjectUtils.equals(this.status, v))
              {
            this.status = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Amount
     *
     * @return String
     */
    public String getAmount()
    {
        return amount;
    }

                        
    /**
     * Set the value of Amount
     *
     * @param v new value
     */
    public void setAmount(String v) 
    {
    
                  if (!ObjectUtils.equals(this.amount, v))
              {
            this.amount = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Unit
     *
     * @return String
     */
    public String getUnit()
    {
        return unit;
    }

                        
    /**
     * Set the value of Unit
     *
     * @param v new value
     */
    public void setUnit(String v) 
    {
    
                  if (!ObjectUtils.equals(this.unit, v))
              {
            this.unit = v;
            setModified(true);
        }
    
          
              }
  
    /**
     * Get the Price
     *
     * @return String
     */
    public String getPrice()
    {
        return price;
    }

                        
    /**
     * Set the value of Price
     *
     * @param v new value
     */
    public void setPrice(String v) 
    {
    
                  if (!ObjectUtils.equals(this.price, v))
              {
            this.price = v;
            setModified(true);
        }
    
          
              }
  
      
    
                  
    
        private User aUser;

    /**
     * Declares an association between this object and a User object
     *
     * @param v User
     * @throws TorqueException
     */
    public void setUser(User v) throws TorqueException
    {
            if (v == null)
        {
                    setUser_ID(0);
                  }
        else
        {
            setUser_ID(v.getUser_ID());
        }
                aUser = v;
    }

                                            
    /**
     * Get the associated User object
     *
     * @return the associated User object
     * @throws TorqueException
     */
    public User getUser() throws TorqueException
    {
        if (aUser == null && (this.user_ID > 0))
        {
                          aUser = UserPeer.retrieveByPK(SimpleKey.keyFor(this.user_ID));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               User obj = UserPeer.retrieveByPK(this.user_ID);
               obj.addORF_Supplys(this);
            */
        }
        return aUser;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setUserKey(ObjectKey key) throws TorqueException
    {
      
                        setUser_ID(((NumberKey) key).intValue());
                  }
    
    
                  
    
        private ORF aORF;

    /**
     * Declares an association between this object and a ORF object
     *
     * @param v ORF
     * @throws TorqueException
     */
    public void setORF(ORF v) throws TorqueException
    {
            if (v == null)
        {
                    setORF_ID(0);
                  }
        else
        {
            setORF_ID(v.getORF_ID());
        }
                aORF = v;
    }

                                            
    /**
     * Get the associated ORF object
     *
     * @return the associated ORF object
     * @throws TorqueException
     */
    public ORF getORF() throws TorqueException
    {
        if (aORF == null && (this.oRF_ID > 0))
        {
                          aORF = ORFPeer.retrieveByPK(SimpleKey.keyFor(this.oRF_ID));
              
            /* The following can be used instead of the line above to
               guarantee the related object contains a reference
               to this object, but this level of coupling
               may be undesirable in many circumstances.
               As it can lead to a db query with many results that may
               never be used.
               ORF obj = ORFPeer.retrieveByPK(this.oRF_ID);
               obj.addORF_Supplys(this);
            */
        }
        return aORF;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
           */
    public void setORFKey(ObjectKey key) throws TorqueException
    {
      
                        setORF_ID(((NumberKey) key).intValue());
                  }
       
                
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
              fieldNames.add("ORF_SupplyID");
              fieldNames.add("ORF_ID");
              fieldNames.add("User_ID");
              fieldNames.add("Supply_name");
              fieldNames.add("Supply_type");
              fieldNames.add("Quantity");
              fieldNames.add("Status");
              fieldNames.add("Amount");
              fieldNames.add("Unit");
              fieldNames.add("Price");
              fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
          if (name.equals("ORF_SupplyID"))
        {
                return new Integer(getORF_SupplyID());
            }
          if (name.equals("ORF_ID"))
        {
                return new Integer(getORF_ID());
            }
          if (name.equals("User_ID"))
        {
                return new Integer(getUser_ID());
            }
          if (name.equals("Supply_name"))
        {
                return getSupply_name();
            }
          if (name.equals("Supply_type"))
        {
                return getSupply_type();
            }
          if (name.equals("Quantity"))
        {
                return getQuantity();
            }
          if (name.equals("Status"))
        {
                return getStatus();
            }
          if (name.equals("Amount"))
        {
                return getAmount();
            }
          if (name.equals("Unit"))
        {
                return getUnit();
            }
          if (name.equals("Price"))
        {
                return getPrice();
            }
          return null;
    }
    
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
          if (name.equals(ORF_SupplyPeer.ORF_SUPPLYID))
        {
                return new Integer(getORF_SupplyID());
            }
          if (name.equals(ORF_SupplyPeer.ORF_ID))
        {
                return new Integer(getORF_ID());
            }
          if (name.equals(ORF_SupplyPeer.USER_ID))
        {
                return new Integer(getUser_ID());
            }
          if (name.equals(ORF_SupplyPeer.SUPPLY_NAME))
        {
                return getSupply_name();
            }
          if (name.equals(ORF_SupplyPeer.SUPPLY_TYPE))
        {
                return getSupply_type();
            }
          if (name.equals(ORF_SupplyPeer.QUANTITY))
        {
                return getQuantity();
            }
          if (name.equals(ORF_SupplyPeer.STATUS))
        {
                return getStatus();
            }
          if (name.equals(ORF_SupplyPeer.AMOUNT))
        {
                return getAmount();
            }
          if (name.equals(ORF_SupplyPeer.UNIT))
        {
                return getUnit();
            }
          if (name.equals(ORF_SupplyPeer.PRICE))
        {
                return getPrice();
            }
          return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
        {
                return new Integer(getORF_SupplyID());
            }
              if (pos == 1)
        {
                return new Integer(getORF_ID());
            }
              if (pos == 2)
        {
                return new Integer(getUser_ID());
            }
              if (pos == 3)
        {
                return getSupply_name();
            }
              if (pos == 4)
        {
                return getSupply_type();
            }
              if (pos == 5)
        {
                return getQuantity();
            }
              if (pos == 6)
        {
                return getStatus();
            }
              if (pos == 7)
        {
                return getAmount();
            }
              if (pos == 8)
        {
                return getUnit();
            }
              if (pos == 9)
        {
                return getPrice();
            }
              return null;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
          save(ORF_SupplyPeer.getMapBuilder()
                .getDatabaseMap().getName());
      }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
       * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
       *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
          try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
      }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
          if (!alreadyInSave)
        {
            alreadyInSave = true;


  
            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    ORF_SupplyPeer.doInsert((ORF_Supply) this, con);
                    setNew(false);
                }
                else
                {
                    ORF_SupplyPeer.doUpdate((ORF_Supply) this, con);
                }
            }

                      alreadyInSave = false;
        }
      }


                    
      /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  oRF_SupplyID ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
            setORF_SupplyID(((NumberKey) key).intValue());
        }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
            setORF_SupplyID(Integer.parseInt(key));
        }

  
    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
          return SimpleKey.keyFor(getORF_SupplyID());
      }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
       * It then fills all the association collections and sets the
     * related objects to isNew=true.
       */
      public ORF_Supply copy() throws TorqueException
    {
        return copyInto(new ORF_Supply());
    }
  
    protected ORF_Supply copyInto(ORF_Supply copyObj) throws TorqueException
    {
          copyObj.setORF_SupplyID(oRF_SupplyID);
          copyObj.setORF_ID(oRF_ID);
          copyObj.setUser_ID(user_ID);
          copyObj.setSupply_name(supply_name);
          copyObj.setSupply_type(supply_type);
          copyObj.setQuantity(quantity);
          copyObj.setStatus(status);
          copyObj.setAmount(amount);
          copyObj.setUnit(unit);
          copyObj.setPrice(price);
  
                    copyObj.setORF_SupplyID(0);
                                                                  
        
        return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public ORF_SupplyPeer getPeer()
    {
        return peer;
    }

    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("ORF_Supply:\n");
        str.append("ORF_SupplyID = ")
           .append(getORF_SupplyID())
           .append("\n");
        str.append("ORF_ID = ")
           .append(getORF_ID())
           .append("\n");
        str.append("User_ID = ")
           .append(getUser_ID())
           .append("\n");
        str.append("Supply_name = ")
           .append(getSupply_name())
           .append("\n");
        str.append("Supply_type = ")
           .append(getSupply_type())
           .append("\n");
        str.append("Quantity = ")
           .append(getQuantity())
           .append("\n");
        str.append("Status = ")
           .append(getStatus())
           .append("\n");
        str.append("Amount = ")
           .append(getAmount())
           .append("\n");
        str.append("Unit = ")
           .append(getUnit())
           .append("\n");
        str.append("Price = ")
           .append(getPrice())
           .append("\n");
        return(str.toString());
    }
}
